package com.xc.dsocket.server.filenio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class W1 {

    public void writeMsg(String msg){
        try {
            FileOutputStream fout = new FileOutputStream("D:/temp/dsocket.txt",true);
            FileChannel channel = fout.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(1024);
            buffer.put(msg.getBytes());
            buffer.flip();
            channel.write(buffer);
            fout.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        W1 w1 = new W1();
        w1.writeMsg("hello");
    }
}
